package com.situ.springboot.service.impl;

import com.situ.springboot.mapper.StudentMapper;
import com.situ.springboot.pojo.Student;
import com.situ.springboot.pojo.StudentSearchVO;
import com.situ.springboot.service.IStudentService;
import com.situ.springboot.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements IStudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> selectAll() {
        return studentMapper.selectAll();
    }

    @Override
    public void deleteById(Integer id) {
        studentMapper.deleteById(id);
    }

    // Service:业务
    @Override
    public LayUITableResult selectByPage(Integer page, Integer limit, StudentSearchVO studentSearchVO) {
        // 查询当前页的数据
        // select * from student limit (page-1)*limit,limit
        int offset = (page - 1) * limit;
        List<Student> list = studentMapper.selectByPage(offset, limit, studentSearchVO);

        // 查询总的数量
        long count = studentMapper.selectTotalCount(studentSearchVO);

        return LayUITableResult.ok(list, count);
    }

    @Override
    public void add(Student student) {
        studentMapper.add(student);
    }

    @Override
    public Student selectById(Integer id) {
        return studentMapper.selectById(id);
    }

    @Override
    public void update(Student student) {
        studentMapper.update(student);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        // delete form student where id in(10,16);
        for (Integer id : ids) {
            deleteById(id);
        }
    }
}
